

import 'package:flutter/material.dart';
import 'package:jicaimao_flutter/utils/sp_key.dart';
import 'package:jicaimao_flutter/utils/sp_utils.dart';
import 'package:jicaimao_flutter/views/splash/splashPage.dart';
import 'package:jicaimao_flutter/views/tab_main_page.dart';

class AppInitPage extends StatefulWidget{
  @override
  _AppInitPageState createState()=> _AppInitPageState();

}

class _AppInitPageState extends State<AppInitPage>{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      backgroundColor: Colors.white,
      body: Container(
        width: double.infinity,
          height: double.infinity,
        child: Image.asset('images/jcm_startthe.png',width: double.infinity,height: double.infinity,),
      )
    );
  }

  @override
  void initState() {
    super.initState();
    _saveSp();
    countDown();
  }

  void countDown() {

    var _duration = new Duration(seconds: 3);
    new Future.delayed(_duration, go2HomePage);
  }

  void go2HomePage() {
    Navigator.push(
      context,
      MaterialPageRoute(
          builder: (context) => goPage()),
    );



  }

  void _saveSp() async {
    await SpUtils.getInstance(); //等待Sp初始化完成
    SpUtils.putString(SpKey.KEY_USER_ID, '176e978c5626450aace911308f089568');
  }

  goPage() {
    bool isFrist = SpUtils.getBool(SpKey.KEY_SPLASH_MODEL);
//    isFrist = true;
    print(isFrist.toString());
    if (isFrist == null || isFrist) {
      return SplashPage();
    } else {
      return TabMainPage();
    }
  }
}